package com.zhouxiaoge.集合;

import java.util.SortedSet;
import java.util.TreeSet;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-05-08 10:24
 */

public class TreeSetTest {
    public static void main(String[] args) {
        SortedSet<Item> items = new TreeSet<>();
        items.add(new Item("AAA", 7890, 1));
        items.add(new Item("CCC", 4567, 2));
        items.add(new Item("BBB", 1234, 3));
        items.add(new Item("BBB", 2222, 4));
        System.out.println(items);
        SortedSet<Item> sortByDescripton = new TreeSet<>((a, b) -> {
            String aDescription = a.getDescription();
            String bDescription = b.getDescription();
            return aDescription.compareTo(bDescription);
        });
        sortByDescripton.addAll(items);
        System.out.println(sortByDescripton);
        SortedSet<Item> sortByAge = new TreeSet<>((a, b) -> {
            int aAge = a.getAge();
            int bAge = b.getAge();

            return Integer.compare(aAge, bAge);
        });
        sortByAge.addAll(items);
        System.out.println(sortByAge);


    }
}
